package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/31 09:13
 */
public class LS0205 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode head = new ListNode();
        int cur = 0;
        ListNode l  = head;
        while (l1!=null || l2!=null||cur!=0) {
            int a = l1!=null ? l1.val:0;
            int b = l2!=null ? l2.val:0;

            int val = (a + b + cur) % 10;
            cur =  (a + b + cur) / 10;
            l.next = new ListNode(val);
            l = l.next;
            l1 = l1!=null ? l1.next:l1;
            l2=l2!=null?l2.next:l2;

        }

        return head.next;
    }
}
